﻿@{
    int page = ViewBag.PageIndex;
    string kw = ViewBag.Keyword;
    int i = 0;
}
@model Projects
<div class="content-box">
    <div class="content-box-header">
        <h3 style="cursor: s-resize;">股票配资方案管理</h3>

        <div class="clear"></div>
    </div>
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
            <div class="">
                <form action="@Url.DomainRouteUrl(AreasConfig.Admin, "Index", "Stock")">
                    <select name="depart" class="">
                        <option value="1">--选择方案状态--</option>
                        <option value="2">Option 2</option>
                        <option value="3">Option 3</option>
                        <option value="4">Option 4</option>
                    </select>
                    <input type="text" name="kw" value="" class="text-input" placeholder="按登录名，姓名，手机号搜索" />
                    <button type="submit" value="">搜索</button>
                </form>
            </div>
            <table>
                <thead>
                    <tr>
                        <th>
                            <input class="check-all" type="checkbox">
                        </th>
                        <th>方案号</th>
                        <th>用户</th>
                        <th>投资本金(元)</th>
                        <th>配资金额(元)</th>
                        <th>亏损警告线(元)</th>
                        <th>亏损平仓线(元)</th>
                        <th>交易时间</th>
                        <th>方案状态</th>
                        <th style="text-align: center">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.Items)
                    {
                        i++;
                        <tr class="@(i%2 == 0 ? "" : "alt-row")">
                            <td>
                                <input type="checkbox">
                            </td>
                            <td><a href="@Url.DomainRouteUrl(AreasConfig.Admin,new{controller="Stock",action="Detail",id=item.ProjectId})">@item.ProjectNumber</a></td>
                            <td><a href="@Url.DomainRouteUrl(AreasConfig.Admin,new{controller="User",action="Detail",id=item.UserId})">@item.User.UserName</a></td>
                            <td>@item.Principal</td>
                            <td>@item.MatchEndowment</td>
                            <td>@item.LossWarLine</td>
                            <td>@item.LossOpenLine</td>
                            <td>@item.StartProjectTime.ToString("yyyy-MM-dd")</td>
                            <td>@CommonFunc.GetProjectState(item.ProjectState)</td>
                            <td projectid="@item.ProjectId">
                                @if (item.ProjectState == (int)ProjectStateEnum.CapitalVerification)
                                {
                                    <a href="javascript:void(0);" mark="CapitalVerification">【验资】</a>
                                }
                                @if (item.ProjectState == (int)ProjectStateEnum.OpenAccount)
                                {
                                    <a href="javascript:void(0);" mark="OpenAccount">【开户】</a>
                                }
                                @if (item.ProjectState > (int)ProjectStateEnum.OpenAccount && item.ProjectState != (int)ProjectStateEnum.Termination && item.ProjectState != (int)ProjectStateEnum.SubmitTermination)
                                {
                                    <a href="javascript:void(0);" mark="Termination">【终止】</a>
                                }
                                @if (item.ProjectState == (int)ProjectStateEnum.Termination || item.ProjectState == (int)ProjectStateEnum.SubmitTermination)
                                {
                                    <a href="javascript:void(0);" class="disable">【已终止】</a>
                                }
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        //验资
        $("a[mark=CapitalVerification]").bind("click", function () {
            var $this = $(this);
            if (!confirm("你确定要通过验资？")) {
                return false;
            }
            var projectId = $this.parent("td").attr("projectId");
            $.jajax({
                url: "@Url.DomainRouteUrl(AreasConfig.Admin, new { controller = "Stock", action = "CapitalVerification"})",
                params: { id: projectId, page: "@Page", kw: "@kw" },
                callback: function (ret) {
                    if (ret) {
                        $.jalert(ret.data);
                        window.location.href = "@Url.DomainRouteUrl(AreasConfig.Admin,new{controller="Stock",action="Index",page=page,kw=kw})";
                    }
                }
            });
        });

        //开户
        $("a[mark=OpenAccount]").bind("click", function () {
            var $this = $(this);
            var projectId = $this.parent("td").attr("projectId");
            $.StockWindow({
                id: "StockProjectOpenAccount",
                title: "方案开户",
                width: 450,
                content: '<form mark="StockForm"><div class="db-m">' +
                    '<div class="db-con">' +
                    '<div style="padding:10px 0;" class="ui-sub-form">' +
                    '<label class="ui-label">交易账户</label><input type="text" name="TradingAccount" id="TradingAccount" style="width:200px;" class="ui-input">' +
                    '</div>' +
                    '<div style="padding:10px 0 20px;" class="ui-sub-form">' +
                    '<label class="ui-label">交易密码</label><input name="TradingPassword" id="TradingPassword" type="text" style="width:200px;" class="ui-input">' +
                    '</div>' +
                    '<div style="padding:20px 0 10px 100px;" class="ui-sub-form">' +
                    '<input type="button" id="ConfirmOpenAccount" value="确认" class="button red">' +
                    '<input type="button" id="Cancel" value="取消" class="button grey">' +
                    '</div>' +
                    '</div>' +
                    '</div></form>',
                callback: function () {
                    $("#Cancel").bind("click", function () {
                        $("#StockProjectOpenAccount").CloseWindow();
                    });
                    $("#ConfirmOpenAccount").bind("click", function () {
                        var $TradingAccount = $("#TradingAccount");
                        var $TradingPassword = $("#TradingPassword");

                        var tradingAccount = $.trim($TradingAccount.val());
                        var tradingPassword = $.trim($TradingPassword.val());
                        if (!tradingAccount) {
                            $.jalert("交易账户不能为空");
                            $TradingAccount.focus();
                            return;
                        }
                        if (!tradingPassword) {
                            $.jalert("交易密码不能为空");
                            $TradingPassword.focus();
                            return;
                        }
                        $.jajax({
                            url: "@Url.DomainRouteUrl(AreasConfig.Admin, new {controller = "Stock", action = "OpenAccount"})",
                            params: { id: projectId, tradingAccount: tradingAccount, tradingPassword: tradingPassword },
                            callback: function (ret) {
                                if (ret) {
                                    $.jalert(ret.data);
                                    window.location.href = "@Url.DomainRouteUrl(AreasConfig.Admin,new{controller="Stock",action="Index",page=page,kw=kw})";
                                }
                            }
                        });
                    });
                }
            });

        });
        //终止操盘
        $("a[mark=Termination]").bind("click", function () {
            var $this = $(this);
            var projectId = $this.parent("td").attr("projectId");
            if (!confirm("你确定要终止操盘？")) {
                return false;
            }
            $.jajax({
                url: "@Url.DomainRouteUrl(AreasConfig.Admin, new { controller = "Stock", action = "Termination" })",
                params: { id: projectId, page: "@Page", kw: "@kw" },
                callback: function (ret) {
                    if (ret) {
                        $.jalert(ret.data);
                        window.location.href = "@Url.DomainRouteUrl(AreasConfig.Admin,new{controller="Stock",action="Index",page=page,kw=kw})";
                    }
                }
            });

        });
    });
</script>